package com.tianpengtech.front.web.qiniu;

import com.jfinal.upload.UploadFile;
import com.qiniu.common.QiniuException;
import com.tianpengtech.common.util.QiNiuUtil;
import com.tianpengtech.front.web.common.controller.BaseController;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/31 0031.
 */
public class QiNiuController extends BaseController {

    public void index(){
        String token=QiNiuUtil.getToken();
        Map<String,String> tokens=new HashMap<>();
        tokens.put("uptoken",token);
        setAttr("","");
        renderJson(tokens);
    }

    public void upload() throws Exception {
        UploadFile upfile=getFile();
        try {
            String upload = QiNiuUtil.upload(new FileInputStream(upfile.getFile()));
            upfile.getFile().delete();
            renderText(upload);
        } catch (Exception e) {
            throw e;
        }

    }

}
